package com.iclient.web.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;

import weibo4j.Oauth;
import weibo4j.http.AccessToken;
import weibo4j.model.WeiboException;

@Controller
public class OAuthController {
	@Autowired
	private RedisTemplate<String, String> redisTemplate;
	
	@RequestMapping(value="/sina/oauth/index.html")
	public String index(){
		return "/sina/oauth";
	}
	
	@RequestMapping(value="/sina/oauth.json")
	@ResponseBody
	public void oauth(String code) throws WeiboException{
		Oauth oauth = new Oauth();
		AccessToken accessToken = oauth.getAccessTokenByCode(code);
		redisTemplate.opsForValue().set("auth:accesstoken", JSONObject.toJSONString(accessToken));
	}
	

}
